﻿layui.config({
    base: "/static/js/"
}).use(['form', 'layer', 'jquery', "address"], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        address = layui.address;

    //注册按钮
    form.on("submit(register)", function (data) {
        $(this).text("提交中...").attr("disabled", "disabled").addClass("layui-disabled");
        var jsonObj = $("#regForm").serializeObject();
        console.log("user register ", jsonObj);

        if (jsonObj.password.length < 6 || jsonObj.password.length > 20) {
            layer.msg("密码长度在6-20位之间");
            return false;
        }
        if (jsonObj.password != jsonObj.ConfirmPassword) {
            layer.msg("两次输入的密码不一致");
            return false;
        }

        $.post("/Login/UserReg/", jsonObj, function (res) {
            if (res.isSuccess) {
                layer.alert(res.msg, {icon: 6, closeBtn: 0}, function () {
                    window.location.href = "/";
                });
            } else {
                layer.msg(res.msg);
                $("#imgCheckCode").click();
                $("#btnReg").text("注册").removeAttr("disabled").removeClass("layui-disabled");
                return false;
            }
        });
        return false;
    });
    address.provinces();

});
